/*
 * Copyright (C) 2012 Rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.entities;

import rpg.Location;
import rpg.entities.area.Renderable;
import rpg.gfx.Bitmap;
import rpg.maps.Map;

/**
 * rothens.tarhely.biz
 *
 * @author Rothens
 */
public abstract class Entity {

    public static int nextID = 0;
    
    protected Location currentLocation;
    protected Location previousLocation;
    protected Map map;
    protected Entity parent;
    public int xRenderOffset = -10;
    public int yRenderOffset = -10;
    public int id;
    
    public Entity(){
        id = nextID;
        nextID++;
    }
    
    public Entity(Location loc){
        this();
        currentLocation = loc;
        previousLocation = loc;
        map = loc.getMap();
    }

    public boolean isPassable() {
        return false;
    }
    
    public abstract boolean tick();

    public abstract Bitmap getDrawGraphics();
    
    public void setAllLocations(Location loc){
        currentLocation = previousLocation = loc;
    }

    public Location getCurrentLocation() {
        return currentLocation;
    }

    public void setCurrentLocation(Location currentLocation) {
        this.currentLocation = currentLocation;
    }

    public Location getPreviousLocation() {
        return previousLocation;
    }

    public void setPreviousLocation(Location previousLocation) {
        this.previousLocation = previousLocation;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    public boolean isInView(Renderable r) {
        int diff = 32;

        if (r.topLeft.getX() - diff < currentLocation.getX() && r.bottomRight.getX() + diff > currentLocation.getX()
                && r.topLeft.getY() - diff < currentLocation.getY() && r.bottomRight.getY() + diff > currentLocation.getY()) {
            xRenderOffset = currentLocation.getX() - r.topLeft.getX();
            yRenderOffset = currentLocation.getY() - r.topLeft.getY();
            return true;
        }
        return false;
    }

    public int getxRenderOffset() {
        return xRenderOffset;
    }

    public void setxRenderOffset(int xRenderOffset) {
        this.xRenderOffset = xRenderOffset;
    }

    public int getyRenderOffset() {
        return yRenderOffset;
    }

    public void setyRenderOffset(int yRenderOffset) {
        this.yRenderOffset = yRenderOffset;
    }

    @Override
    public int hashCode() {
        return id;
    }
    
    
    
}
